package com.yunji.base.dao.impl;

import com.yunji.base.bo.MemberQueryBO;
import com.yunji.base.dao.IMemberDao;
import com.yunji.base.mapper.IMemberMapper;
import com.yunji.common.base.BaseDaoImpl;
import com.yunji.common.model.domain.MemberDO;
import com.yunji.common.utils.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : peter-zhu
 * @date : 2024/12/11 13:39
 * @description : TODO
 **/
@Repository
public class MemberDaoImpl extends BaseDaoImpl<IMemberMapper, MemberDO> implements IMemberDao {


    @Override
    public MemberDO searchMember(MemberQueryBO build) {
        return lambdaQuery()
                .eq(StringUtils.isNotEmpty(build.getPhone()), MemberDO::getPhone, build.getPhone())
                .eq(StringUtils.isNotEmpty(build.getOpenId()), MemberDO::getOpenid, build.getOpenId())
                .eq(StringUtils.isNotEmpty(build.getName()), MemberDO::getName, build.getName())
                .one();
    }

    @Override
    public List<String> searchTableField(MemberQueryBO param) {
        return this.baseMapper.searchTableField(param);
    }

    @Override
    public boolean updateOpenId(String phone, String openId) {
        return lambdaUpdate().set(MemberDO::getOpenid, openId).eq(MemberDO::getPhone, phone).update();
    }
}
